﻿/**
* 该类为时钟原理类
* @author lbynet
* @version 0.1
*/

package {
	import Date;
	import flash.display.Sprite;
	import flash.events.Event;
	public class Clock extends Sprite {
		
		private var bg_mc:Sprite;
		private var hour:Number;
		private var minute:Number;
		private var second:Number;
		private var _hours:Sprite;
		private var _minutes:Sprite;
		private var _seconds:Sprite;

		public function Clock(bg_mc:Sprite,h:Sprite,m:Sprite,s:Sprite) {
			this.bg_mc = bg_mc;
			this._hours = h;
			this._minutes = m;
			this._seconds = s;
			
			init();
		}
		private function init() {
			this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
		}

		private function enterFrameHandler(event:Event) {

			var now:Date = new Date(); // 构造一个Date实例
			hour = now.getHours();   //获取系统当前的时，分，秒	
			minute = now.getMinutes();
			second = now.getSeconds();
			//下面控制时针、分针、秒针的旋转规律、旋转角度 ，后面进行具体解释
			_hours.rotation = hour*30 + Math.floor(minute*6/12);
			_minutes.rotation = minute*6 + Math.floor(second*6/60);
			_seconds.rotation = second*6;
			
			bg_mc._txt.text = "" + hour + ":" + minute + ":" +second;

		}
	}
}